import React, { useState } from 'react'
import PubSub from 'pubsub-js'

export default function Search() {
  //关键字状态
  let [keyword, setKeyword] = useState('');
  //受控组件的回调
  let change = (e) => {
    //更新状态
    setKeyword(e.target.value);
  }
  //点击搜索的事件回调
  let search = async () => {
    // 发布
    PubSub.publish('keyword',keyword)
  }
  return (
    <div className="form">
      <input type="text" value={keyword} onChange={change} /><button onClick={search}>搜索</button>
    </div>
  )
}
